<template>
<div style="z-index:5;left: 0;top: 0;position: fixed;height: 100%;width: 100%;background-color:white">
    <img src="../../../../assets/changepsw/back.png" class="img_back" @click="goper">
    <div class="div1">
        <span>身份验证</span>
    </div>
    <div style="margin-left:22px;margin-right:22px;margin-top:20px">
        <div>
            <span class="span1">验证当前密码</span>
        </div>
        <div style="margin-top:40px;border-bottom: 0.7px solid rgb(215, 215, 215, 0.7);">
            <span style="font-size:18px">密码</span>
            <input type="password" placeholder="请输入当前密码" class="input" v-model="psw" @focus="InputFocus(0)" @blur="InputBlur">
            <img src="../../../../assets/changepsw/false.png" class="img_false" v-show="psw" @click="deletepsw">
        </div>
        <div class="div33" :style="WhichInput==0?InputStyle[0]+MyDiv33Width:InputStyle[1]+'width:0px'"></div>
        <div style="margin-top:15px">
            <span class="span2" @click="forgetpsw">忘记密码</span>
        </div>
        <div class="div2" :style="psw?'':'background-color: rgb(108, 216, 255);opacity: 0.6;'" @click="next">
            <span>下一步</span>
        </div>
    </div>
    <div class="div3" v-show="ErrorMessage" :style="ErrorPosition+ErrorPosition2">
        <img src="../../../../assets/changepsw/error.png" class="img_error">
        <span style="margin-left:15px">密码验证错误</span>
    </div>
    <ImgLock class="img_lock"></ImgLock>
</div>
</template>

<script>
import ImgLock from './img/img_lock.vue'
export default {
    name:'checkpsw',
    components:{ImgLock},
    data(){
        return{
            psw:'',
            ErrorMessage:0,
            ErrorPosition:'',
            ErrorPosition2:'',
            WhichInput:99,
            InputStyle:['border-bottom: 0.7px solid rgb(40, 144, 255);','border-bottom: 0.7px solid rgb(229, 229, 229);'],
            MyDiv33Width:'',
            username:'',
        }
    },
    methods:{
        deletepsw(){
            this.psw=''
        },
        goper(){this.$router.replace({name:'intercept_backspace'})},
        forgetpsw(){this.$router.push({name:'forgetpsw'})},
        next(){
            // this.ErrorMessage=!this.ErrorMessage
            if(this.psw){
                this.$addr.get(`user/check_psw?`,{
                    params:{
                        oldPassword:this.psw
                    }
                }).then(
                    response=>{
                        console.log('验证密码请求成功',response.data);
                            if(response.data.state == 4002){
                                this.ErrorMessage=1
                            }else{
                                this.$router.push({name:'changepsw',params:{'username':this.username}})
                            }
                    },error=>{
                        this.$message({
                            message:'验证密码请求失败，请重新登陆',
                            type:'error'
                        })
                        console.log("验证密码请求失败",error.message);
                        this.$router.replace({name:'login'})
                    }
                )
            }
        },
        InputFocus(index){
            this.WhichInput=index
        },
        InputBlur(){
            this.WhichInput=99
        }
    },
    watch:{
        psw(value){
            if(value.length > 25){
                this.psw=value.slice(0,25)
            }
        },
        ErrorMessage(value){
            if(value == 1){
                let num = -295
                let ok = 0
                var id = setInterval(() => {
                    this.ErrorPosition='margin-top:'+num+'px'
                    // console.log(this.ErrorPosition,'@');
                    if(num < -315){
                        ok = 1
                        num++
                    }else if(ok){
                        if(num > -310){
                            clearInterval(id);
                        }else{
                            num++
                        }
                    }else{
                        num--
                    }
                }, 3);
                var id3 = setTimeout(() => {
                    let num2=1
                    var id2 = setInterval(() => {
                        //下面的分号非常细节
                        this.ErrorPosition2=';opacity:'+num2
                        // console.log(this.ErrorPosition2,'%');
                        if(num2 < 0.05){
                            clearInterval(id2)
                            clearTimeout(id3)
                            this.ErrorMessage=0
                            this.ErrorPosition=this.ErrorPosition2=''
                        }else{
                            num2-=0.05
                        }
                    }, 15);
                }, 1000);
            }
        }
    },
    mounted(){
        this.MyDiv33Width='width:'+(window.innerWidth-44)+'px;'
        this.$addr.get(`user/get_by_uid`).then(
            response=>{
                console.log('获取用户数据请求成功',response.data);
                this.username=response.data.data.username
            },error=>{
                this.$message({
                    message:'获取用户数据请求失败，请重新登陆',
                    type:'error'
                })
                console.log("获取用户数据请求失败",error.message);
                // this.$router.replace({name:'login'})
            }
        )
    }
}
</script>

<style scoped>
.div33{
    margin-top: -.7px;
    position: absolute;
    transition: border-bottom .5s ease-in-out,width .5s ease-out;
}
.div1{
    /* background-color: rgb(77, 190, 255);
    background-color: rgb(134, 215, 255); */
    background: linear-gradient(to right,rgb(110, 207, 255),rgb(24, 166, 249));
    color: white;
    text-align: center;
    width: 100%;
    padding-top: 23px;
    padding-bottom: 15px;
    user-select: none;
}
.span1{
    font-size: 28px;
    font-weight: 500;
}
.input{
    font-size: 16px;
    padding: 10px;
    height: 20px;
    border-style: none;
    outline: none;
    margin-left: 15px;
    width: 160px;
    margin-bottom: 1px;
}
input::-webkit-input-placeholder{
    color: rgb(174, 174, 174);
}
.img_back{
    margin-top: 28px;
    left: 14px;
    height: 18px;
    position: absolute;
}
.img_false{
    position: fixed;
    height: 15px;
    margin-top: 14px;
    right: 40px;
}
.span2{
    font-size: 14px;
    color: rgb(40, 144, 255);
}
.div2{
    margin-top: 40px;
    background-color: rgb(85, 190, 255);
    font-size: 18px;
    color: white;
    margin-left: -10px;
    margin-right: -10px;
    padding-top: 10px;
    padding-bottom: 10px;
    text-align: center;
    border-radius: 5px;
    cursor: pointer;
    user-select: none;
}
.div3{
    position: absolute;
    width: 94%;
    font-size: 18px;
    text-align: center;
    padding-bottom: 15px;
    padding-top: 15px;
    margin-left: 10px;
    border-radius: 5px;
    background-color: white;
    box-shadow: 0px 1px 5px 1px rgb(212, 212, 212) ;
    /* margin-top: -310px; */
    margin-top: -294px;
}
.img_error{
    height: 26px;
    position: absolute;
    margin-left: -15px;
    margin-top: 1px;
}
.img_lock{
    position: fixed;
    width: 40%;
    top: 170px;
    z-index: -1;
}
</style>